package com;

import java.util.ArrayList;
import java.util.List;

class School {
    private String name;
    private List<Department> departments;

    public School(String name) {
        this.name = name;
        this.departments = new ArrayList<>();
    }

    public void addDepartment(Department department) {
        departments.add(department);
    }

    public List<Department> getDepartments() {
        return departments;
    }

    public String getName() {
        return name;
    }
}

class Department {
    private String name;
    private List<Instructor> instructors;
    private List<Subject> subjects;

    public Department(String name) {
        this.name = name;
        this.instructors = new ArrayList<>();
        this.subjects = new ArrayList<>();
    }

    public void addInstructor(Instructor instructor) {
        instructors.add(instructor);
    }

    public void addSubject(Subject subject) {
        subjects.add(subject);
    }

    public List<Instructor> getInstructors() {
        return instructors;
    }

    public List<Subject> getSubjects() {
        return subjects;
    }

    public String getName() {
        return name;
    }
}

class Instructor {
    private String name;
    private List<Subject> subjects;

    public Instructor(String name) {
        this.name = name;
        this.subjects = new ArrayList<>();
    }

    public void teachSubject(Subject subject) {
        subjects.add(subject);
        subject.setInstructor(this);
    }

    public List<Subject> getSubjects() {
        return subjects;
    }

    public String getName() {
        return name;
    }
}

class Student {
    private String name;
    private List<Subject> subjects;

    public Student(String name) {
        this.name = name;
        this.subjects = new ArrayList<>();
    }

    public void enrollIn(Subject subject) {
        subjects.add(subject);
        subject.addStudent(this);
    }

    public List<Subject> getSubjects() {
        return subjects;
    }

    public String getName() {
        return name;
    }
}

class Subject {
    private String name;
    private Instructor instructor;
    private List<Student> students;

    public Subject(String name) {
        this.name = name;
        this.students = new ArrayList<>();
    }

    public void setInstructor(Instructor instructor) {
        this.instructor = instructor;
    }

    public void addStudent(Student student) {
        students.add(student);
    }

    public Instructor getInstructor() {
        return instructor;
    }

    public List<Student> getStudents() {
        return students;
    }

    public String getName() {
        return name;
    }
}

public class A1_3 {
    public static void main(String[] args) {
        School school = new School("Moonshot University");

        Department computerScience = new Department("Computer Science");
        Department math = new Department("Mathematics");

        school.addDepartment(computerScience);
        school.addDepartment(math);

        Instructor professorX = new Instructor("Professor X");
        Instructor professorY = new Instructor("Professor Y");

        computerScience.addInstructor(professorX);
        math.addInstructor(professorY);

        Subject javaProgramming = new Subject("Java Programming");
        Subject calculus = new Subject("Calculus");

        computerScience.addSubject(javaProgramming);
        math.addSubject(calculus);

        professorX.teachSubject(javaProgramming);
        professorY.teachSubject(calculus);

        Student student1 = new Student("Alice");
        Student student2 = new Student("Bob");

        student1.enrollIn(javaProgramming);
        student2.enrollIn(calculus);

        System.out.println("School: " + school.getName());
        for (Department department : school.getDepartments()) {
            System.out.println("Department: " + department.getName());
            for (Instructor instructor : department.getInstructors()) {
                System.out.println("\tInstructor: " + instructor.getName());
                for (Subject subject : instructor.getSubjects()) {
                    System.out.println("\t\tSubject: " + subject.getName());
                    Instructor subjectInstructor = subject.getInstructor();
                    if (subjectInstructor != null) {
                        System.out.println("\t\t\tInstructor: " + subjectInstructor.getName());
                    }
                    for (Student student : subject.getStudents()) {
                        System.out.println("\t\t\t\tStudent: " + student.getName());
                    }
                }
            }
        }
    }
}